package com.jy.appmarket.cards;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jy.app.market.idata.card.CardSubjectHeader;
import com.jy.appmarket.R;
import com.jy.appmarket.utils.LoadImageUtils;
import com.jy.appmarket.utils.UITools;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * 类说明：
 * 
 * @author Baker.li
 * @date 2015年8月21日
 * @version 1.0
 */

public class SubjectHeaderUICard extends BaseUICard {

	private CardSubjectHeader mSubHeader;

	public SubjectHeaderUICard(Context context, CardSubjectHeader subHeader) {
		super(context, R.layout.subject_header_card);
		mSubHeader = subHeader;
		setShadow(false);
	}

	@Override
	public int getType() {
		return 5;
	}

	@Override
	public void setupInnerViewElements(ViewGroup parent, View view) {
		super.setupInnerViewElements(parent, view);
		if (mSubHeader == null) {
			return;
		}
		ImageView image = parent.findViewById(R.id.subject_header_image);
		int imageWidth = UITools.getDeviceScreenWidthHeight(getContext())[0];
		int imageHeight = getHeaderImageHeight();
		ViewGroup.LayoutParams lp = image.getLayoutParams();
		lp.width = imageWidth;
		lp.height = imageHeight;
		image.setLayoutParams(lp);
		
		TextView detail = parent.findViewById(R.id.subject_header_detail);
		ImageLoader.getInstance().displayImage(mSubHeader.getImageUrl(), image, LoadImageUtils.getBannerDisplayOption(getContext()));
		detail.setText("　　" + Html.fromHtml(mSubHeader.getDetail()));
	}
	
	@Override
	public int getMarginTop(){
		return 0; //返回0，则在顶部没有空隙
	}
	
	private int getHeaderImageHeight(){
		int [] screenSize = UITools.getDeviceScreenWidthHeight(getContext());
		int screenW = screenSize[0];
		
		float h = ((float)screenW * 3) / 7; // 宽高比为7:3
		
		return (int)h;	
	}
}